<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDelete">
        <span>全部删除</span>&nbsp;&nbsp;&nbsp;
        <span @click="isDelete=false">完成</span>
      </div>
      <van-icon v-else @click="isDelete=true" name="delete" />
    </van-cell>
    <van-cell v-for="(value , index) in history" :key="index"
      @click="addSearch(value)" :title="value">
      <van-icon v-show="isDelete" @click="deleteHistory(index)" name="close" />
    </van-cell>
  </div>
</template>

<script>

export default {
  name: 'SearchHistory',
  components: {},
  props: {
    history: {
      type: Array,
      require: true
    }
  },
  data () {
    return {
      isDelete: false
    }
  },
  computed: {},
  watch: {},
  created () { },
  mounted () { },
  methods: {
    deleteHistory (index) {
      this.history.splice(index, 1)
      this.$store.commit('setHistory', this.history)
    },
    addSearch (val) {
      if (!this.isDelete) {
        this.$emit('addSearch', val)
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
